<style>
    table{font-size: 14px;}
    .btn-group{margin-top: 20px;}
    .btn{width: 150px;height: 45px;}
    .td_1{width: 120px;height: 50px;}
    td{padding-left: 30px;}
    .col-md-12{background-color: #fff;}
    .medication-line{border-top:1px solid #ddd;}
    .medication{margin-top: 20px;font-size: 18px;font-weight:900;}
    .insulin-value{border-radius:3px;width: 100px;}
    .default_medicinal{border-top:1px solid #ddd;margin-top: 20px;padding-bottom: 30px;}
    .default_insulin{height: 34px;width: 200px;color:#999999;border-radius:3px;margin-top: 10px;margin-left: 30px;}
</style>
<body>
<div class="btn-group">
    <a href="details?id=<?php if(!empty($_GET['id'])){echo $_GET['id'];}?>"><button type="button" class="btn btn-primary btn-top">基 础 档 案</button></a>
    <a href="measure?id=<?php if(!empty($_GET['id'])){echo $_GET['id'];}?>"><button type="button" class="btn btn-default btn-top">测 糖 记 录</button></a>
    <a href="insulin?id=<?php if(!empty($_GET['id'])){echo $_GET['id'];}?>"><button type="button" class="btn btn-default btn-top">用 药 记 录</button></a>
</div>
<table>
    <tbody>
        <tr><td>&nbsp;</td></tr>
        <tr>
            <td class="td_1">姓名：</td>
            <td width=250>{{$result->name}}</td>
            <td width=120>性别：</td>
            <td width=250>
                @if($result->gender == 1)
                    男
                @elseif($result->gender == 2)
                    女
                @else
                    保密
                @endif
            </td>
            <td width=140>年龄：</td>
            <td>
                @if(!empty($result->birth_at))
                    {{round(getMonthNum($result->birth_at,date('Y-m-d H:i:s',time()),true / 12))}}
                @endif
            </td>
        </tr>
        <tr>
            <td class="td_1">证件类型：</td>
            <td>
                @switch($result->papers_type)
                    @case(1)
                        身份证
                        @break
                    @default
                        @break
                @endswitch
            </td>
            <td>体重：</td>
            <td>{{$result->weight}} kg</td>
            <td>身高：</td>
            <td>{{$result->height}} cm</td>
        </tr>
        <tr>
            <td class="td_1">证件号码：</td>
            <td>{{$result->papers}}</td>
            <td>BMI：</td>
            <td>
                @if(!empty(($result->height / 100) * ($result->height / 100)))
                    {{round($result->weight / (($result->height / 100) * ($result->height / 100)),2)}}
                @endif
            </td>
            <td>糖尿病类型：</td>
            <td>
                @switch($result->dm_type)
                    @case(0)
                        其它
                        @break
                    @case(1)
                        1型糖尿病
                        @break
                    @case(2)
                        2型糖尿病
                        @break
                    @case(3)
                        妊娠型糖尿病
                        @break
                    @case(4)
                        糖尿病前期
                        @break
                    @case(5)
                        特殊型糖尿病
                        @break
                    @default
                        @break
                @endswitch
            </td>
        </tr>
        <tr>
            <td class="td_1">糖龄：</td>
            <td>
                @if(!empty($result->dm_age))
                    {{getMonthNum($result->dm_age,date('Y-m-d H:i:s',time()))}}
                @endif
            </td>
            <td>治疗方式：</td>
            <td>
                @switch($result->treatment)
                    @case(1)
                        口服药
                        @break
                    @case(2)
                        胰岛素治疗
                        @break
                    @case(3)
                        饮食调控
                        @break
                    @case(4)
                        运动调控
                        @break
                    @default
                        @break
                @endswitch
            </td>
            <td>是否饮酒：</td>
            <td>
                @if($result->is_drink==1)
                    是
                @else
                    否
                @endif
            </td>
        </tr>
        <tr>
            <td class="td_1">是否吸烟：</td>
            <td>
                @if($result->is_smoke==1)
                    是
                @else
                    否
                @endif
            </td>
            <td>并发症：</td>
            <td colspan='3'>{{$result->complication}}</td>
        </tr>
        <tr><td>&nbsp;</td></tr>
    </tbody>
</table>

<div class="medication-line">
    <div class="medication">用药信息</div>
    <table>
        <tr>
            <td class="td_1" style="width: 200px;">胰岛素 1 & 胰岛素 2</td>
            <td>早餐前</td>
            <td>中餐前</td>
            <td>晚餐前</td>
            <td>睡前</td>
        </tr>
        <tr>
            {{--<td class="td_1">--}}
                {{--<select class="form-control insulin">--}}
                    {{--<option value="0">甘精胰岛素</option>--}}
                {{--</select>--}}
            {{--</td>--}}
            <td class="td_1"><input type="text" style="width: 150px;" class="form-control insulin-value" placeholder="" value="<?php echo empty($insulin[0]['insulin']) ? '' : $insulin[0]['insulin'];?>"></td>
            <td><input type="text" class="form-control insulin-value" placeholder="" value="<?php echo empty($insulin[0]['before_breakfast']) ? '' : $insulin[0]['before_breakfast'];?>"></td>
            <td><input type="text" class="form-control insulin-value" placeholder="" value="<?php echo empty($insulin[0]['before_lunch']) ? '' : $insulin[0]['before_lunch'];?>"></td>
            <td><input type="text" class="form-control insulin-value" placeholder="" value="<?php echo empty($insulin[0]['before_dinner']) ? '' : $insulin[0]['before_dinner'];?>"></td>
            <td><input type="text" class="form-control insulin-value" placeholder="" value="<?php echo empty($insulin[0]['before_sleep']) ? '' : $insulin[0]['before_sleep'];?>"></td>
        </tr>
        <tr>
            {{--<td class="td_1">--}}
                {{--<select class="form-control insulin">--}}
                    {{--<option value="0">甘精胰岛素</option>--}}
                    {{--<option value="1">甘精胰岛素</option>--}}
                    {{--<option value="2">甘精胰岛素</option>--}}
                {{--</select>--}}
            {{--</td>--}}
            <td class="td_1"><input type="text" style="width: 150px;" class="form-control insulin-value" placeholder="" value="<?php echo empty($insulin[1]['insulin']) ? '' : $insulin[1]['insulin'];?>"></td>
            <td><input type="text" class="form-control insulin-value" value="<?php echo empty($insulin[1]['before_breakfast']) ? '' : $insulin[1]['before_breakfast'];?>"></td>
            <td><input type="text" class="form-control insulin-value" value="<?php echo empty($insulin[1]['before_lunch']) ? '' : $insulin[1]['before_lunch'];?>"></td>
            <td><input type="text" class="form-control insulin-value" value="<?php echo empty($insulin[1]['before_dinner']) ? '' : $insulin[1]['before_dinner'];?>"></td>
            <td><input type="text" class="form-control insulin-value" value="<?php echo empty($insulin[1]['before_sleep']) ? '' : $insulin[1]['before_sleep'];?>"></td>
        </tr>
    </table>
</div>
<div class="default_medicinal">
    <div class="medication">患者短/速效推荐用药</div>
    <select class="form-control default_insulin" id="sara">
        @if(empty($user_medicinal['SARA']))
            <option value="0">请选择默认药品</option>
        @endif
        @foreach ($medicinal as $item)
            @if(in_array($item->insulin_type,['SHORT_ACTING','RAPID_ACTING']))
                @if(!empty($user_medicinal['SARA']) && $user_medicinal['SARA'] == $item->id)
                    <option value="{{$item->id}}" selected>{{$item->medicinal_cn}}</option>
                @else
                    <option value="{{$item->id}}">{{$item->medicinal_cn}}</option>
                @endif
            @endif
        @endforeach
    </select>
    <div class="medication">患者基础/中效推荐用药</div>
    <select class="form-control default_insulin" id="basal">
        @if(empty($user_medicinal['BASAL']))
            <option value="0">请选择默认药品</option>
        @endif
        @foreach ($medicinal as $item)
            @if(in_array($item->insulin_type,['INTERMEDIATE_ACTING','BASAL']))
                @if(!empty($user_medicinal['BASAL']) && $user_medicinal['BASAL'] == $item->id)
                    <option value="{{$item->id}}" selected>{{$item->medicinal_cn}}</option>
                @else
                    <option value="{{$item->id}}">{{$item->medicinal_cn}}</option>
                @endif
            @endif
        @endforeach
    </select>
</div>

</body>

<script>
    $('#sara').change(function () {
        var id = <?php echo $_GET['id']?>;
        var medicinal_id = $(this).val();
        var data = {'id':id,'medicinal_id':medicinal_id,'default_type':'SARA'};
        ajaxDefault(data);
    });

    $('#basal').change(function () {
        var id = <?php echo $_GET['id']?>;
        var medicinal_id = $(this).val();
        var data = {'id':id,'medicinal_id':medicinal_id,'default_type':'BASAL'};
        ajaxDefault(data);
    });
    
    function ajaxDefault(data) {
        var index = layer.load();
        $.ajax({
            url:"{{admin_url('user/default_medicinal')}}",
            type: "post",
            data:data,
            success:function (res) {
                layer.close(index)
                if(res.code!=0) {
                    layer.msg('操作失败');
                }
            }
        })
    }
</script>
